#include <iostream>
#include "ProcessPool.hpp"

// 输入格式有误警告
void Usage(std::string proc)
{
    std::cout << "UsageError=>you should input: " << proc << " worker_num" << std::endl;
}

int main(int argc, char *argv[])
{
    // 规定输入的指令格式：./processpool num(num为创建的子进程个数)
    if (argc != 2)
    {
        Usage(argv[0]);
        return UsageError;
    }
    int worker_num = std::stoi(argv[1]);

    ProcessPool *pp = new ProcessPool(worker_num, Work);
    // 1.初始化进程池
    pp->InitProcessPool();
    //2.派发任务给指定的worker
    pp->DispatchTask();
    //3.清空进程池
    pp->CleanProcessPool();

    delete pp;



    // std::vector<Channel> channels; // 管理管道

    // // 1.初始化进程池
    // InitProcessPool(worker_num, channels, Work);
    // // DebugPrint(channels);

    // // 2.派发任务给指定的worker
    // DispatchTask(channels);

    // // 3.清空进程池
    // CleanProcessPool(channels);

    // sleep(100);
    return OK;
}